package com.ruoyi.jetLinks.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jetLinks.domain.DevProtocol;
import com.ruoyi.jetLinks.service.IDevProtocolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 协议管理Controller
 * 
 * @author lxx
 * @date 2022-02-07
 */
@Api(tags = "协议管理")
@RestController
@RequestMapping("/jetLinks/devProtocol")
public class DevProtocolController extends BaseController {
    @Autowired
    private IDevProtocolService devProtocolService;

    /**
     * 查询协议管理列表
     */
    @ApiOperation("分页查询协议管理列表")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevProtocol devProtocol) {
        startPage();
        List<DevProtocol> list = devProtocolService.selectDevProtocolList(devProtocol);
        return getDataTable(list);
    }

    /**
     * 导出协议管理列表
     */
    @ApiOperation("导出协议管理列表")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:export')")
    @Log(title = "协议管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevProtocol devProtocol)
    {
        List<DevProtocol> list = devProtocolService.selectDevProtocolList(devProtocol);
        ExcelUtil<DevProtocol> util = new ExcelUtil<DevProtocol>(DevProtocol.class);
        util.exportExcel(response, list, "协议管理数据");
    }

    /**
     * 获取协议管理详细信息
     */
    @ApiOperation("获取协议管理详细信息")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(devProtocolService.selectDevProtocolById(id));
    }

    /**
     * 新增协议管理
     */
    @ApiOperation("新增协议管理")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:add')")
    @Log(title = "协议管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevProtocol devProtocol) {
        return toAjax(devProtocolService.insertDevProtocol(devProtocol));
    }

    /**
     * 修改协议管理
     */
    @ApiOperation("修改协议管理")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:edit')")
    @Log(title = "协议管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevProtocol devProtocol) {
        return toAjax(devProtocolService.updateDevProtocol(devProtocol));
    }

    /**
     * 删除协议管理
     */
    @ApiOperation("删除协议管理")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:remove')")
    @Log(title = "协议管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(devProtocolService.deleteDevProtocolByIds(ids));
    }

    /**
     * 定时任务状态修改
     */
    @PreAuthorize("@ss.hasPermi('jetLinks:devProtocol:changeState')")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeState")
    public AjaxResult changeStatus(@RequestBody DevProtocol devProtocol) {
        DevProtocol newJob = devProtocolService.selectDevProtocolById(devProtocol.getId());
        newJob.setState(devProtocol.getState());
        return toAjax(devProtocolService.updateDevProtocol(newJob));
    }

    /**
     * 查询产品列表
     */
    @ApiOperation("查询协议管理")
    @GetMapping("/queryAll")
    public AjaxResult queryAll(DevProtocol devProtocol) {
        return AjaxResult.success(devProtocolService.selectDevProtocolList(devProtocol));
    }
}
